package com.qying.sort;

/**
 * 选择排序
 */
public class SelectSort {

    public static void main(String[] args) {
        int[] arr = Number.arr;

        for (int i : arr) {
            System.out.print(i + ",");
        }
        System.out.println();

       /* for (int i = 0; i < arr.length; i++) {
            int minIndex = i;
            for (int j = i; j < arr.length; j++) {
                if (arr[j] < arr[minIndex]) //找到最小的数
                    minIndex = j; //将最小数的索引保存
            }
            int temp = arr[minIndex];
            arr[minIndex] = arr[i];
            arr[i] = temp;
        }*/


        for (int i = 0; i< arr.length; i++) {
            int index = i;

            for (int j = i;j< arr.length;j++){
                if (arr[index] > arr[j]) {
                    index = j;
                }
            }
            int temp = arr[index];
            arr[index] = arr[i];
            arr[i] = temp;

        }

        for (int i : arr) {
            System.out.print(i + ",");
        }
    }
}
